package it.trekker.sensors;

public class OrientationCoord {

	private float azimuth;
	private float pitch;
	private float roll;

	public OrientationCoord() {
	}

	public OrientationCoord(float x, float y, float z) {
		azimuth = x;
		pitch = y;
		roll = z;
	}

	public OrientationCoord(float[] coord) {
		if(coord != null) {
			azimuth = coord[0];
			pitch = coord[1];
			roll = coord[2];
		}
	}

	public float getAzimuth() {
		return azimuth;
	}

	public void setAzimuth(float azimuth) {
		this.azimuth = azimuth;
	}

	public float getPitch() {
		return pitch;
	}

	public void setPitch(float pitch) {
		this.pitch = pitch;
	}

	public float getRoll() {
		return roll;
	}

	public void setRoll(float roll) {
		this.roll = roll;
	}

	public void setCoordinates(float[] coord) {
		azimuth = coord[0];
		pitch = coord[1];
		roll = coord[2];
	}

	public void getCoordinatesAsFloatArray() {
		float[] coord = new float[3];

		coord[0] = azimuth;
		coord[1] = pitch;
		coord[2] = roll;
	}

	public String getCompassString() {
		
		String result;
		
		if (azimuth < 22)
			result = "N";
		else if (azimuth >= 22 && azimuth < 67)
			result = "NE";
		else if (azimuth >= 67 && azimuth < 112)
			result = "E";
		else if (azimuth >= 112 && azimuth < 157)
			result = "SE";
		else if (azimuth >= 157 && azimuth < 202)
			result = "S";
		else if (azimuth >= 202 && azimuth < 247)
			result = "SW";
		else if (azimuth >= 247 && azimuth < 292)
			result = "W";
		else if (azimuth >= 292 && azimuth < 337)
			result = "NW";
		else if (azimuth >= 337)
			result = "N";
		else
			result = "";
		
		return result;
	}
}
